package com.ynny.student.systemDB;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("userManage")
public class UserManageImpl implements UserManage {
    @Autowired
private JdbcTemplate jdbcTemplate;
    @Override
    public boolean login(User user) {
        //定义SQL查询语句，实现根据用户信息查询users表中的用户记录
        String sql = "select * users where number=? and password=? and identity=?";
        //定义数组来存放SQL语句的参数
        Object[] obj = new Object[]{
                user.getNumber(),
                user.getPassword(),
                user.getIdentity()
        };
        //创建一个BeanPropertyRowMapper对象
        RowMapper<User> rowMapper;
        rowMapper = new BeanPropertyRowMapper<User>(User.class);

        //执行SQL查询语句，并通过rowMapper返回存放User类对象的List集合
         List<User> user_db = jdbcTemplate.query(sql,rowMapper,obj);


         //判断记录记录不为空
        if (!user_db.isEmpty()){
            return true;
        }
        return false;
    }


    @Override
    public void quit() {
        System.out.println("退出登录");

    }
}
